

#include <bits/stdc++.h>
using namespace std;

struct LNode{
    int data;
    LNode *next;
};

int main(){
    int n, k;
    cin >> n >> k;
    LNode *h = new LNode;
    LNode *t = h;
    for(int i = 1; i <= n; ++i){
        LNode *p = new LNode;
        p->data = i;
        t->next = p;
        t = p;
    }
    t->next = h->next;
    LNode *pre = h;
    LNode *cur = h->next;
    LNode *Next = cur->next;
    int id = 1;
    while(cur->next != cur){
        Next = cur->next;
        if(id == k){
            pre->next = Next;
            cout << cur->data << " ";
            delete cur;
            cur = Next;
            id = 1;
        }else{
            id++;
            pre = cur;
            cur = Next;
        }
    }
    cout << '\n' << cur->data;
    return 0;
}